package model;

import com.ansj.vec.Word2VEC;
import entity.News;
import utils.IOUtils;
import utils.VecModel;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by 梅晨 on 2017/7/20.
 */
public class Train extends PreProcess {
    private String trainLibSVMPath;
    public Train(HashMap<String, Integer> filePathClaMap,String modelPath,String dicPath,String trainLibSVMPath) {
        super(filePathClaMap,modelPath,dicPath,trainLibSVMPath);
        this.trainLibSVMPath = trainLibSVMPath;
    }

    public void run()throws IOException{
        List<News> newsList = newObj();
        List<String> dicContent = new ArrayList<String>();
        for(News news : newsList){
            dicContent.add(news.getDicContent());
        }
        IOUtils.saveFile(dicContent,dicPath);
        VecModel vecModel = new VecModel(modelPath,dicPath);
        vecModel.train();
        Word2VEC word2VEC = vecModel.loadModel();
        VecProcess(newsList,word2VEC);
        String[] trainArgs = {trainLibSVMPath};//directory of training file
        model.svm_train.main(trainArgs);
    }
}
